//全选
$(function(){
    $("#zcheckbox").change(function(){//判断全选框的改变
        var flage =$(this).is(":checked");//全选选中为true，否则为false
        $("input[type=checkbox]").each(function(){
            $(this).prop("checked",flage);
        })
    })
})

//获取勾选的行数据的id并将其用,拼接成字符串
function getIds() {
    var str = '';
    for(var i = 0; i < document.getElementsByName('ids').length; i++) {
        if(document.getElementsByName('ids')[i].checked) {
            if(str == '') {
                str += document.getElementsByName('ids')[i].value;
            } else {
                str += ',' + document.getElementsByName('ids')[i].value;
            }
        }
    }
    return str;
}

//检索
function searchs(){
    top.jzts();
    $("#form").submit();
}

//查看详情
function detail(id) {
    top.jzts();
    var diag = new top.Dialog();
    diag.Drag = true;
    diag.Title = "查看详情";
    diag.URL = path + '/admin/circleInfo/detailPage?id='+ id;
    diag.Width = 1050;
    diag.Height = 550;
    diag.CancelEvent = function(){ //关闭事件
        diag.close();
    };
    diag.show();
}

//上下架
function onOrOff(id, state, msg, currentPage) {
    var warning = "下架后将不可在该圈子下继续发表文章！";
    var remind = "您确定要" + msg + "吗?";
    if (state == 1) { //想要下架
        remind = warning + "<br/>" + remind;
    }
    bootbox.confirm(remind, function(result) {
        if(result) {
            top.jzts();
            var url = path +'/admin/circleInfo/onOrOff?id=' + id + "&state=" + state;
            $.get(url,function(data){
                top.hangge();
                bootbox.dialog({
                    message: "<span class='bigger-110'>" + data.msg + "</span>",
                    buttons: {
                        "button":{
                            "label":"确定",
                            "className":"btn-sm btn-success",
                            "callback": function() {
                                nextPage(currentPage);
                            }
                        }
                    }
                });
            });
        };
    });
}

//新增
function add(currentPage){
    top.jzts();
    var diag = new top.Dialog();
    diag.Drag = true;
    diag.Title ="新增";
    diag.URL = path + '/admin/circleInfo/addPage';
    diag.Width = 1050;
    diag.Height = 980;
    diag.CancelEvent = function(){//关闭事件
        if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
            if(currentPage == '0'){
                top.jzts();
                setTimeout("self.location=self.location",100);
            }else{
                nextPage(currentPage);
            }
        }
        diag.close();
    };
    diag.show();
}

//编辑
function edit(id, currentPage){
    top.jzts();
    var diag = new top.Dialog();
    diag.Drag = true;
    diag.Title ="编辑";
    diag.URL = path + '/admin/circleInfo/editPage?id=' + id;
    diag.Width = 1050;
    diag.Height = 980;
    diag.CancelEvent = function(){//关闭事件
        if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
            if(currentPage == '0'){
                top.jzts();
                setTimeout("self.location=self.location",100);
            }else{
                nextPage(currentPage);
            }
        }
        diag.close();
    };
    diag.show();
}

//切换所属一级类别获取相应的二级类别
$("#mainTypeCode").change(function () {
    var mainTypeCode = $("#mainTypeCode").val();
    getMenuTwoLevelConfigByMainTypeCode(mainTypeCode);
});

function getMenuTwoLevelConfigByMainTypeCode(mainTypeCode) {
    $.ajax({
        url : path + "/admin/menuTwoLevelConfig/getMenuTwoLevelConfigByMainTypeCode",
        type : "post",
        dataType : "json",
        data : {"mainTypeCode" : mainTypeCode, "status" : 2}, //status为2表示，查询列表（保留下架状态的二级类别，即所有，上架和下架都要有）
        success : function (data) {
            if (data.code == 200) {
                var list = data.data;
                var html = "";
                html += "<option value=''>全部</option>";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].menuCode + "'>" + list[i].menuName + "</option>";
                }
                $("#subTypeCode").html(html);
            } else {
                top.hangge();
                bootbox.dialog({
                    message: "<span class='bigger-110'>" + data.msg + "</span>",
                    buttons: {
                        "button" : {
                            "label" : "确定",
                            "className" : "btn-sm btn-success"
                        }
                    }
                });
            }
        }
    });
}

//如果没有选择数据提示信息
function batchErrorMessage() {
    bootbox.dialog({
        message: "<span class='bigger-110'>您没有选择任何内容!</span>",
        buttons:{
            "button":{
                "label":"确定",
                "className":"btn-sm btn-success"
            }
        }
    });
    $("#zcheckbox").tips({
        side:3,
        msg:'点这里全选',
        bg:'#AE81FF',
        time:8
    });
}

//批量上架
function batchOn(currentPage) {
    bootbox.confirm("确定要批量上架选中的数据吗?", function(result) {
        if(result) {
            var str = getIds();
            if(str==''){
                batchErrorMessage();
            }else{
                top.jzts();
                $.ajax({
                    type: "POST",
                    url: path +'/admin/circleInfo/batchOn',
                    data: {ids : str},
                    dataType:'json',
                    cache: false,
                    success: function(data){
                        top.hangge();
                        bootbox.dialog({
                            message: "<span class='bigger-110'>"+data.msg+"</span>",
                            buttons: {
                                "button":{
                                    "label":"确定",
                                    "className":"btn-sm btn-success",
                                    "callback": function() {
                                        nextPage(currentPage);
                                    }
                                }
                            }
                        });
                    }
                });
            }
        }
    });
}

//批量下架
function batchOff(currentPage) {
    bootbox.confirm("确定要批量下架选中的数据吗?", function(result) {
        if(result) {
            var str = getIds();
            if(str==''){
                batchErrorMessage();
            }else{
                top.jzts();
                $.ajax({
                    type: "POST",
                    url: path +'/admin/circleInfo/batchOff',
                    data: {ids : str},
                    dataType:'json',
                    cache: false,
                    success: function(data){
                        top.hangge();
                        bootbox.dialog({
                            message: "<span class='bigger-110'>"+data.msg+"</span>",
                            buttons: {
                                "button":{
                                    "label":"确定",
                                    "className":"btn-sm btn-success",
                                    "callback": function() {
                                        nextPage(currentPage);
                                    }
                                }
                            }
                        });
                    }
                });
            }
        }
    });
}

//批量选入精彩页面
function batchIsWonderful(currentPage) {
    bootbox.confirm("确定要将选中的数据批量选入精彩页面吗?", function(result) {
        if(result) {
            var str = getIds();
            if(str==''){
                batchErrorMessage();
            }else{
                top.jzts();
                $.ajax({
                    type: "POST",
                    url: path +'/admin/circleInfo/batchIsWonderful',
                    data: {ids : str},
                    dataType:'json',
                    cache: false,
                    success: function(data){
                        top.hangge();
                        bootbox.dialog({
                            message: "<span class='bigger-110'>"+data.msg+"</span>",
                            buttons: {
                                "button":{
                                    "label":"确定",
                                    "className":"btn-sm btn-success",
                                    "callback": function() {
                                        nextPage(currentPage);
                                    }
                                }
                            }
                        });
                    }
                });
            }
        }
    });
}

//批量撤出精彩页面
function batchIsNotWonderful(currentPage) {
    bootbox.confirm("确定要将选中的数据批量撤出精彩页面吗?", function(result) {
        if(result) {
            var str = getIds();
            if(str==''){
                batchErrorMessage();
            }else{
                top.jzts();
                $.ajax({
                    type: "POST",
                    url: path +'/admin/circleInfo/batchIsNotWonderful',
                    data: {ids : str},
                    dataType:'json',
                    cache: false,
                    success: function(data){
                        top.hangge();
                        bootbox.dialog({
                            message: "<span class='bigger-110'>"+data.msg+"</span>",
                            buttons: {
                                "button":{
                                    "label":"确定",
                                    "className":"btn-sm btn-success",
                                    "callback": function() {
                                        nextPage(currentPage);
                                    }
                                }
                            }
                        });
                    }
                });
            }
        }
    });
}


